package com.shujia

object Demo7ScalaExtend {
  def main(args: Array[String]): Unit = {
    val b: A = new B("002", "李四", 18)
    println(b.toString)
  }
}

class A(id: String, name: String) {
  println("A的构造方法")
  // 定义即赋值
  val _id: String = id
  val _name: String = name


  override def toString = s"A(${_id}, ${_name})"
}

/**
 * 继承还是使用extends关键字
 * 但是在继承就需要调用父类的构造方法
 */
class B(id: String, name: String, age: Int) extends A(id, name) {
  println("B中的构造方法")
  val _age: Int = age

  override def toString = s"B(${_id}, ${_name}, ${_age})"

}